| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 93 | jQuery(document).ready(function () { |
||
| 94 | var findItemByID = function (id) { |
||
| 95 | var credentials, foundItem = false; |
||
| 96 | credentials = angular.element('#app-content-wrapper').scope().credentials; |
||
| 97 | angular.forEach(credentials, function (credential) { |
||
| 98 | if (credential.credential_id === id) { |
||
| 99 | foundItem = credential; |
||
| 100 | } |
||
| 101 | }); |
||
| 102 | return foundItem; |
||
| 103 | }; |
||
| 104 | jQuery(document).on('click', '.undoDelete', function () { |
||
| 105 | var credential = findItemByID($(this).attr('data-item-id')); |
||
| 106 | angular.element('#app-content-wrapper').scope().recoverCredential(credential); |
||
| 107 | //Outside anglular we need $apply |
||
| 108 | angular.element('#app-content-wrapper').scope().$apply(); |
||
| 109 | }); |
||
| 110 | jQuery(document).on('click', '.undoRestore', function () { |
||
| 111 | var credential = findItemByID($(this).attr('data-item-id')); |
||
| 112 | angular.element('#app-content-wrapper').scope().deleteCredential(credential); |
||
| 113 | //Outside anglular we need $apply |
||
| 114 | angular.element('#app-content-wrapper').scope().$apply(); |
||
| 115 | }); |
||
| 116 | var adjustControlsWidth = function (r) { |
||
| 117 | if ($('#controls').length) { |
||
| 118 | var controlsWidth; |
||
| 119 | // if there is a scrollbar … |
||
| 120 | if ($('#app-content').get(0)) { |
||
| 121 | if ($('#app-content').get(0).scrollHeight > $('#app-content').height()) { |
||
| 122 | if ($(window).width() > 768) { |
||
| 123 | controlsWidth = $('#content').width() - $('#app-navigation').width() - OC.Util.getScrollBarWidth(); |
||
| 124 | if (!$('#app-sidebar').hasClass('hidden') && !$('#app-sidebar').hasClass('disappear')) { |
||
| 125 | controlsWidth -= $('#app-sidebar').width(); |
||
| 126 | } |
||
| 127 | } else { |
||
| 128 | controlsWidth = $('#content').width() - OC.Util.getScrollBarWidth(); |
||
| 129 | } |
||
| 130 | } else { // if there is none |
||
| 131 | if ($(window).width() > 768) { |
||
| 132 | controlsWidth = $('#content').width() - $('#app-navigation').width(); |
||
| 133 | if (!$('#app-sidebar').hasClass('hidden') && !$('#app-sidebar').hasClass('disappear')) { |
||
| 134 | //controlsWidth -= $('#app-sidebar').width(); |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | controlsWidth = $('#content').width(); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | } |
||
| 141 | var magic; |
||
| 142 | if (r) { |
||
| 143 | magic = 0; |
||
| 144 | } else { |
||
| 145 | magic = 85; |
||
| 146 | } |
||
| 147 | $('#controls').css('width', controlsWidth + magic); |
||
| 148 | $('#controls').css('min-width', controlsWidth + magic); |
||
| 149 | } |
||
| 150 | }; |
||
| 151 | /* |
||
| 152 | $(window).resize(adjustControlsWidth, 400); |
||
| 153 | setTimeout(function () { |
||
| 154 | adjustControlsWidth(true); |
||
| 155 | }, 200);*/ |
||
| 156 | |||
| 157 | //@Fack this |
||
| 158 | /* |
||
| 159 | $(document).on('click', '#app-navigation-toggle', function () { |
||
| 160 | setTimeout(function () { |
||
| 161 | if ($('#app-content').css('transform').toString().indexOf('matrix') >= 0) { |
||
| 162 | $('#passman-controls').css('width', 'calc( 100% - 245px)'); |
||
| 163 | $('#passman-controls').css('top', '0'); |
||
| 164 | } else { |
||
| 165 | $('#passman-controls').css('left', 0); |
||
| 166 | $('#passman-controls').css('top', '44px'); |
||
| 167 | $('#passman-controls').css('width', '100%'); |
||
| 168 | } |
||
| 169 | }, 350); |
||
| 170 | });*/ |
||
| 171 | }); |
||
| 172 | }()); |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.